var numSteps = 5;
var minColor, maxColor, unselColor, selColor;
var colors = Array();

function makeMarkerColors()
{
  w("Generating colors");

  minColor = new Color(189, 0, 38);
  maxColor = new Color(255, 255, 178);
  unselColor = new Color(0, 0, 0);
  selColor = Color.parseHex("eeeeff");

  colors[4] = new Color(189, 0, 38);
  colors[3] = new Color(240, 59, 32);
  colors[2] = new Color(253, 141, 60);
  colors[1] = new Color(254, 204, 92);
  colors[0] = new Color(255, 255, 178);
  return;

  for (i = 0; i < numSteps; ++i)
  {
    colors[i] = Color.lerp(i, 0, numSteps - 1, minColor, maxColor);
    w('<div style="background-color:#' + colors[i].toHex() + '">' + colors[i]
        + '</div>');
  }
}


function getIcon(color, number, selected)
{
  var numString = String(number);

  var colorStr = color.toHex().toLowerCase();
  // if (number > 9) numString = "9+";

  var key = colorStr + "_" + numString + "_" + selected;
  if (!(key in markerIcons))
  {
    var iconOptions = {};
    iconOptions.regularColor = "#" + colorStr;
    iconOptions.primaryColor = "#" + (selected ? selColor.toHex() : colorStr);
    iconOptions.label = numString;
    
    if (color == colors[numSteps-1] && !selected) iconOptions.labelColor = "#fff";
    
    // iconOptions.labelColor = "#" + (selected ? selColor.toHex() :
    // unselColor.toHex());
    // iconOptions.addStar = selected;
    
    
    markerIcons[key] = MapIconMaker.createLabeledMarkerIcon(iconOptions);
    markerIcons[key].iconOptions = iconOptions;
  }
  return markerIcons[key];
}

/**
 * 
 * @param bldgid
 * @param color
 * @param number
 * @param selected
 * @return
 */
function setMarkerIcon(bldgid, color, number, selected)
{
  var marker = markers[bldgid];
  var icon = getIcon(color, number, selected);
  marker.setImage(icon.image);
  marker.iconOptions = icon.iconOptions;
}

function setMarkerIconSelected(bldgid, selected)
{
  var marker = markers[bldgid];
  var iconOptions = marker.iconOptions;
  var icon = getIcon(Color.parseHex(iconOptions.regularColor),
      iconOptions.label, selected);
  marker.setImage(icon.image);
}

function getColor(val, minVal, maxVal)
{
  var mapped = Math.mapToInt(val, minVal, maxVal, 0, numSteps - 1);
  return colors[mapped];
}

function bounceMarker(marker)
{
  return;
  try {
    marker.enableDragging();
    marker.fc(marker.q);
    marker.p=marker.Yc;
    marker.dc(marker.q);
    marker.disableDragging();
  }
  finally {}
}
